﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Maticsoft.Web.Admin.Info
{
    public partial class News : PageBase
    {
        string Key = string.Empty;
        string ChannelId = string.Empty;
        BLL.News bll = new BLL.News();
        protected void Page_Load(object sender, EventArgs e)
        {
            Check("Content", "read");

            if (!string.IsNullOrEmpty(Request.QueryString["key"]))
            {
                Key = Request.QueryString["key"];
            }
            if (!string.IsNullOrEmpty(Request.QueryString["channelid"]))
            {
                ChannelId = Request.QueryString["channelid"];
            }

            if (!IsPostBack)
            {
                BindData();
            }
        }

        protected void BindData()
        {
            string strWhere = "1=1";
            if (!string.IsNullOrEmpty(Key))
            {
                strWhere += " and title like '%" + Key + "%'";
            }
            if (!string.IsNullOrEmpty(ChannelId))
            {
                strWhere += " and channelId=" + ChannelId;
            }
            //strWhere += " order by newsId desc";


            int recordCount = bll.GetRecordCount(strWhere);
            AspNetPager1.RecordCount = recordCount;
            DataSet ds = bll.GetListByPage(strWhere, "newsId desc", AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex);
            Repeater1.DataSource = ds.Tables[0].DefaultView;
            Repeater1.DataBind();
        }

        protected string GetChannelName(string cid)
        {
            BLL.Channel bllChannel = new BLL.Channel();
            return bllChannel.GetModel(int.Parse(cid)).ChannelName;
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("News.aspx?channelId=" + ddlType.SelectedValue + "&key=" + txtKey.Value.Trim());
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Check("Content", "del");

            string ids = txtIds.Value;
            if (!string.IsNullOrWhiteSpace(ids))
            {
                bll.DeleteByIds(ids);
            }
        }

        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            BindData();
        }
    }
}